//
//  XJWalletChargeFooterView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJWalletChargeFooterView.h"
#import "YYLabel.h"
#import "NSAttributedString+YYText.h"
//#import "AttributedLabel.h" // 富文本


@interface XJWalletChargeFooterView()
//@property(nonatomic, strong) AttributedLabel *chargeProtocolLabel;
@property(nonatomic, strong) YYLabel *chargeProtocolLabel;
@end
@implementation XJWalletChargeFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.chargeProtocolLabel];
}

#pragma mark - 二 lazy

- (YYLabel *)chargeProtocolLabel {
    if (!_chargeProtocolLabel) {
        _chargeProtocolLabel = [[YYLabel alloc] init];
        NSString *wholeStr = @"点击立即支付代表您已同意《未来巴扎充值协议》";
        _chargeProtocolLabel.text = wholeStr;
        NSString *subStr = @"《未来巴扎充值协议》";
//        _chargeProtocolLabel.textAlignment = NSTextAlignmentCenter;
        _chargeProtocolLabel.textColor = XJCOLOR_RGB(157, 165, 168);
        _chargeProtocolLabel.font = XJFONTSET_R(14.0);
        
        //设置文字颜色
        UIColor *blueColor = [UIColor blueColor];
        UIColor *clearColor = [UIColor clearColor];

        NSRange range1 = [wholeStr rangeOfString:subStr];
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:wholeStr attributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
        attributeStr.yy_font = [UIFont systemFontOfSize:14.0];
        attributeStr.yy_lineSpacing = 0;
        attributeStr.yy_alignment = NSTextAlignmentCenter;
        
        [attributeStr yy_setTextHighlightRange:range1 color:blueColor backgroundColor:clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//XJLog(@"点击了 《xxxx充值协议》");
            //回调点击事件
            
            if (self.clickChargeProtocalBlock) {
                self.clickChargeProtocalBlock();
            }
        }];
        
        self.chargeProtocolLabel.attributedText = attributeStr;
    }
    return _chargeProtocolLabel;
}
#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.chargeProtocolLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(10);
        make.centerY.equalTo(self.mas_centerY);
    }];
}
#pragma mark - 四 事件回调



@end
